<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增标签')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-tag-add" >
        <div class="form-group">	
            <label class="col-sm-3 control-label is-required">标签名称：</label>
            <div class="col-sm-8">
                <input id="tagName" name="tagName" class="form-control" type="text" placeholder="标签名" required>
            </div>
        </div>
        <div class="form-group">	
            <label class="col-sm-3 control-label">标签图标：</label>
            <div class="col-sm-8">
                <input  name="tagIco" placeholder="标签图标" class="form-control" type="text">
            </div>
        </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">权限字符：</label>
                <div class="col-sm-8">
                    <input id="perms" name="perms" placeholder="权限字符" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">关键词：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="keywords">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="description">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">标签链接：</label>
                <div class="col-sm-8">
                    <input id="tagUrl" name="tagUrl" placeholder="标签链接" class="form-control" type="text">
                </div>
            </div>

        <div class="form-group">
			<label class="col-sm-3 control-label">标签状态：</label>
			<div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('cms_tag_visible')}">
                    <input type="radio" th:id="${dict.dictCode}" name="visible" th:value="${dict.dictValue}" th:checked="${dict.default}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
			</div>
		</div>
		<div class="form-group">	
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea id="remark" name="remark" placeholder="备注" class="form-control"></textarea>
            </div>
        </div>
    </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
	    var prefix = ctx + "cms/tag";
	
	    $("#form-tag-add").validate({
	    	onkeyup: false,
	        rules: {
	            tagName: {
	                remote: {
	                    url: prefix + "/checkTagNameUnique",
	                    type: "post",
	                    dataType: "json",
	                    data: {
	                        "tagName": function() {
	                            return $.common.trim($("#tagName").val());
	                        }
	                    },
	                    dataFilter: function(data, type) {
	                        return $.validate.unique(data);
	                    }
	                }
	            },
                tagUrl:{
                    remote : {
                        url : prefix + "/checkTagUrlUnique",
                        type : "post",
                        dataType : "json",
                        data : {
                            "tagUrl" : function() {
                                return $.common.trim($(
                                    "#tagUrl").val());
                            }
                        },
                        dataFilter : function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                }
	        },
	        messages: {
	            "tagName": {
	                remote: "标签名已经存在"
	            },
                "tagUrl" : {
                    remote : "标签名路径已经存在"
                }
	        },
	        focusCleanup: true
	    });
	    
	    function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-tag-add').serialize());
	        }
	    }
    </script>
</body>
</html>
